package com.example.parking.controller;/*
 * @author 陈政
 * @date 2020-08-12 19:08
 */

import com.example.parking.service.ParkingService;
import vo.CreateParkingVo;
import vo.HomeParkingVo;
import com.github.pagehelper.PageInfo;
import entity.PageParam;
import entity.Rsp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import pojo.Parking;
import pojo.ParkingInfo;
import java.util.*;

@RestController
public class ParkingController {

    @Autowired
    ParkingService parkingService;

    /**
     * @Author 陈政
     * @Description 添加车位（测试）
     * @Date 14:46 2020-08-25
     * @Param [parking]
     * @return java.lang.Integer
     **/
    @PostMapping("/insertParking")
    public Integer insertParking(@RequestBody Parking parking){
        System.out.println(parking);
        int insert = parkingService.insert(parking);
        return insert;
    }

    /**
     * @Author 陈政
     * @Description 查询车位接口
     * @Date 14:47 2020-08-25
     * @Param [pageParam]
     * @return com.github.pagehelper.PageInfo<vo.HomeParkingVo>
     **/
    @PostMapping("/searchAllParking")
    public PageInfo<HomeParkingVo> searchAllParking(@RequestHeader(value = "userId") String userId,@RequestBody PageParam<Parking> pageParam){
        return parkingService.searchSomeByPage(userId,pageParam);
    }


    /**
     * @Author 陈政
     * @Description 查询车位详情接口
     * @Date 14:48 2020-08-25
     * @Param [parking]
     * @return vo.HomeParkingVo
     **/
    @Cacheable(value = "parkingById")
    @PostMapping("/getParkingById")
    public HomeParkingVo getParkingById(@RequestBody Parking parking){
        return parkingService.selectByPrimaryKey(parking.getParkingId());
    }



    /**
     * @Author 陈政
     * @Description 查询物业接口
     * @Date 14:48 2020-08-25
     * @Param []
     * @return java.util.List
     **/
    @GetMapping("/getProperty")
    public List getProperty(){
        List propertyList = parkingService.getProperties();
        return propertyList;
    }


    /**
     * @Author 陈政
     * @Description 添加车位接口
     * @Date 14:49 2020-08-25
     * @Param [createParkingVo]
     * @return entity.Rsp
     **/
    @PostMapping("/createParking")
    public Rsp createParking(@RequestBody CreateParkingVo createParkingVo){
        //System.out.println(createParkingVo);
        Rsp rsp = parkingService.createParking(createParkingVo);

        return rsp;
    }

    /**
     * @Author 陈政
     * @Description 查询车位数量接口
     * @Date 14:51 2020-08-25
     * @Param []
     * @return java.lang.Integer
     **/
    @GetMapping("/getCounts")
    public Integer getCounts(){
        return parkingService.getCounts();
    }

    /**
     * @Author 陈政
     * @Description 模糊查询车位数量
     * @Date 14:54 2020-08-25
     * @Param [pageParam]
     * @return java.lang.Integer
     **/
    @PostMapping("/getCountsWithKey")
    public Integer getCountsWithKey(@RequestBody PageParam<Parking> pageParam){
        return parkingService.getCountsWithKey(pageParam);
    }

    /**
     * @Author 陈政
     * @Description 上传图片接口
     * @Date 14:54 2020-08-25
     * @Param [file]
     * @return java.lang.Object
     **/
    @RequestMapping(value = "/upload/headImg", method = {RequestMethod.POST})
    public Object headImg(@RequestParam(value="file",required=false) MultipartFile file) throws Exception {
        Map map = parkingService.saveImg(file);
        return map;
    }

    /**
     * @Author 陈政
     * @Description 创建车位详情接口
     * @Date 14:58 2020-08-25
     * @Param [parkingInfo]
     * @return java.lang.Integer
     **/
    @PostMapping("/createParkingInfo")
    public Integer createParkingInfo(@RequestBody ParkingInfo parkingInfo){
        int insert = parkingService.createParkingInfo(parkingInfo);
        return insert;
    }

    @PostMapping("/updateParking")
    public Integer updateParking(@RequestBody PageParam<Parking> pageParam){
        parkingService.updateByPrimaryKeySelective(pageParam);

        return 0;
    }


}
